package com.java.service;

import org.apache.commons.lang.StringUtils;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.java.entity.Department;

/**
 * 部门管理服务
 * @author wqf
 * @version  Nov 24, 2011 11:51:06 AM
 */
@Transactional(propagation = Propagation.REQUIRED,readOnly=false, rollbackFor = Exception.class)
public class DeptService extends BaseService{

	/**
	 * 添加部门
	 * @param dept
	 */
	public void addDepartment(Department dept){
		this.dao.saveObject(dept);
	}
	
	/**
	 * 编辑部门 （for dwr）
	 * @param dept
	 */
	public void editDepartment(Department dept){
		if(null==dept.getId()){
			this.addDepartment(dept);
		}else{
			this.updateDepartment(dept);
		}
	}	
	
	/**
	 * 修改部门
	 * @param dept
	 */
	public void updateDepartment(Department dept){
		this.dao.updateObject(dept);
	}
	
	/**
	 * 删除部门
	 * @param id
	 */
	public void deleteDepartment(Long id){
		Department dept=this.dao.loadObject(Department.class, id);
		this.dao.deleteObject(dept);
	}

	public void deleteDepartmentByIds(String ids){
		if(StringUtils.isNotBlank(ids)){
			String []id  = ids.split(",");
			for(String s:id){
				deleteDepartment(Long.parseLong(s));
			}			
		}	
	}
		
	public Department getDepartmentById(Long id){
		return this.dao.loadObject(Department.class, id);
	}
	
}
